package com.controller.search 
{	
	import com.events.search.ClientSearchEvent;
	import com.service.ClientSearch;
	
	import mx.collections.ArrayCollection;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class ClientSearchController extends AbstractController
	{
		
		[Inject]
		public var clientSearch:ClientSearch;
		
		public function ClientSearchController()
		{
			super();
		}
		
		[EventHandler(event="ClientSearchEvent.GET_ALL_TR_IN",properties="serialnumber")]
		public function getAllTrIn(serialnumber:Number):void{
			model.trInLinks = new ArrayCollection();
			sh.executeServiceCall(clientSearch.getAllTrIn(serialnumber),getAllTrInResult, handleFault );
		}		
		
		private function getAllTrInResult(event:ResultEvent):void
		{
			model.trInLinks = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="ClientSearchEvent.GET_ALL_TR_OUT",properties="serialnumber")]
		public function getAllTrOut(serialnumber:Number):void{
			model.trOutLinks = new ArrayCollection();
			sh.executeServiceCall(clientSearch.getAllTrOut(serialnumber),getAllTrOutResult, handleFault );
		}		
		
		private function getAllTrOutResult(event:ResultEvent):void
		{
			model.trOutLinks= event.result as ArrayCollection;			
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		private function handleFault(event:FaultEvent):void
		{
			Alert.show( event.fault.faultDetail, "Error" );
		}
	}
}